<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            height: 200px;
            width: 200px;
            position: absolute;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div class="box">

    </div>
</body>
<script>
    Object.prototype.el = document.querySelector(".box");
    Object.prototype.el.onmousedown = function (evt) {
        var e = evt || window.event;
        var disX = e.pageX - Object.prototype.el.offsetLeft
        var disY = e.pageY - Object.prototype.el.offsetTop;
        document.onmousemove = function (evt) {
            var e = evt || window.event;
            Object.prototype.el.style.left = e.pageX - disX + "px";
            Object.prototype.el.style.top = e.pageY - disY + "px";
        }
        document.onmouseup = function () {
            document.onmousemove = document.onmouseup = null;
        }
    }
</script>
</html>